package biz.studentMager;

import java.util.Collection;

import models.Student;
import utils.TransactionTemplate;
import dao.StudentDao;
import dao.StudentDaoHbnImpl;

public class StudentMagerBziImpl implements StudentMagerBiz {
	private StudentDao stuDao= new StudentDaoHbnImpl();

	@Override
	public void addStudent(Student stu) {
		try {
			TransactionTemplate.beginTransaction();
			stuDao.addStudent(stu);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public void delStudent(Long stuId) {
		try {
			TransactionTemplate.beginTransaction();
			stuDao.delStudent(stuId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public Collection<Student> selAllStudent() {
		Collection<Student> stus = null;
		try {
			TransactionTemplate.beginTransaction();
			stus=stuDao.selAllStudent();
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}

		return stus;
	}

	@Override
	public Student selStudentById(Long stuId) {
		Student stu = null;
		try {
			TransactionTemplate.beginTransaction();
			stu=stuDao.selStudentById(stuId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}

		return stu;
	}

	@Override
	public void updateStudent(Student stu) {
		try {
			TransactionTemplate.beginTransaction();
			stuDao.updateStudent(stu);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}

	}

}
